package org.teziyou.ticket;

import com.whalin.MemCached.MemCachedClient;
import com.whalin.MemCached.SockIOPool;

public class MemcachedUtil {
	
	public static MemCachedClient client = null;
	
	//111.67.195.91:11211——192.168.100.103:11211
	public static void init(String url, String port) {
		String[] servers = new String[]{url+":"+port};
        SockIOPool pool = SockIOPool.getInstance();  
        pool.setServers(servers);  
        pool.setFailover(true);  
        pool.setInitConn(10);  
        pool.setMinConn(5);  
        pool.setMaxConn(250);  
        pool.setMaintSleep(30);  
        pool.setNagle(false);  
        pool.setSocketTO(3000);  
        pool.setAliveCheck(true);  
        pool.initialize(); 
        client = new MemCachedClient();
	}
	
	
	public static void main(String[] args) {
		/*初始化SockIOPool，管理memcached的连接池*/  
        String[] servers = {"111.67.195.91:12111"};  
        SockIOPool pool = SockIOPool.getInstance();  
        pool.setServers(servers);  
        pool.setFailover(true);  
        pool.setInitConn(10);  
        pool.setMinConn(5);  
        pool.setMaxConn(250);  
        pool.setMaintSleep(30);  
        pool.setNagle(false);  
        pool.setSocketTO(3000);  
        pool.setAliveCheck(true);  
        pool.initialize(); 
        /*建立MemcachedClient实例*/  
        MemCachedClient mc = new MemCachedClient();
        mc.set("foo", "123");
        System.out.println(mc.get("foo"));
	}

}
